<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %><!-- 数据库操作需要 -->        
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
		//获取参数，转换为相应的类型		 
		try {
			Class.forName("org.h2.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return;
		}
		String url="jdbc:h2:d:/CompanyCar/temp/mydbtest";
		Connection conn=null;
		PreparedStatement pstmt  =null;
		String id=request.getParameter("id");
		System.out.println("1");
		//数据库连接与查询过程中可能会引发sql异常
		try {
			//获取数据库连接(url,username,password)			
			conn = DriverManager.getConnection(url,"sa","");
		    String sql="update TrafficViolation set phone_number=?,accident_time=?,violation_type=?,penalty_points=?,vehicle_condition=?,accident_location=?,compensation=?,accident_description=?,remarks=?  where id='"+id+"'";
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, request.getParameter("phone_number"));
			pstmt.setString(2, request.getParameter("accident_time"));
			pstmt.setString(3, request.getParameter("violation_type"));
			pstmt.setString(4, request.getParameter("penalty_points"));
			pstmt.setString(5, request.getParameter("vehicle_condition"));
			pstmt.setString(6, request.getParameter("accident_location"));
			pstmt.setString(7, request.getParameter("compensation"));
			pstmt.setString(8, request.getParameter("accident_description"));
			pstmt.setString(9, request.getParameter("remarks"));
			//循环获取结果集当中的所有数据
			int result=pstmt.executeUpdate();
			System.out.println(result);
			response.sendRedirect("D-Details_Violation.jsp");
			//关闭表达式对象
			pstmt.close();
			
			//关闭数据库			
			conn.close();			
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			//防止数据库未正常关闭
			try{
				if (conn!=null && (!conn.isClosed())){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		// 转发到JSP页面	
%>				
</body>
</html>